# -*- coding: utf-8  -*-
#!/usr/local/bin/python

__author__ = 'jian.yao'

from django.http import HttpResponse, QueryDict

class RequestCheckMiddleware(object):

    def process_request(self, request):
        try:
            u'%s' % request.META.get('QUERY_STRING', '')
            if request.method == "GET":
                request.parameters = request.GET
            elif request.method == "POST":
                request.parameters = request.GET.copy()
                request.parameters.update(QueryDict(request.body))
        except UnicodeDecodeError:
            response = HttpResponse()
            response.status_code = 400
            return response

        return None